package com.maoyan.quickdevelop.system.mapper.dqroom;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.maoyan.quickdevelop.common.core.domain.dqroom.DqBookInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DqBookMapper extends BaseMapper<DqBookInfo> {
    Integer insertOneBookInfo(DqBookInfo dqBookInfo);

    @Select("select count(*) from book_info where room_id = #{roomNumber} and \n" +
            "                             unix_timestamp(book_date) between unix_timestamp(#{bookDate}) and unix_timestamp(#{endDate}) or\n" +
            "                             unix_timestamp(end_date) between unix_timestamp(#{bookDate}) and unix_timestamp(#{endDate})")
    Integer checkRoomIsUse(@Param("roomNumber") String roomNumber, @Param("bookDate") String bookDate, @Param("endDate") String endDate);

    /**
     * 查询制定类型房间的空房间
     **/
    @Select("select distinct dq_room_info.room_number from dq_room_info,book_info where dq_room_info.room_id = #{dqRoomId} and ((dq_room_info.room_number not in (select book_info.room_id from book_info)) or unix_timestamp(book_info.end_date)<sysdate())")
    List<String> selectEmptyRoom(@Param("dqRoomId") Long dqRoomId);

    @Select("select distinct dq_room_info.room_number\n" +
            "from dq_room_info\n" +
            "where dq_room_info.room_id = #{dqRoomId}\n" +
            "    and (dq_room_info.room_number not in (select book_info.room_id from book_info))\n" +
            "union\n" +
            "select distinct room_id\n" +
            "from book_info where book_info.book_date > #{endDate} or book_info.end_date < #{bookDate}")
    List<String> selectUseRoom(@Param("dqRoomId") Long dqRoomId, @Param("bookDate") String bookDate, @Param("endDate") String endDate);

}
